<?php
include_once('./db.conf');
session_start();
// Connects to your Database 
$connection=mysqli_connect(DBHOST, DBUSER, DBPASS,DBDBNAME); 

if(isset($_COOKIE['AdminCookie'])){
if (isset($_POST['OK'])) { // if form has been submitted

	$query2= "call changeSurveyState($_POST[survey],$_POST[tempState])";
	if(!$check2=mysqli_query($connection,$query2))
		echo mysql_error($connection);
	else
		header("Location: indexAdmin.php");
}
else {	
$query1 = "call getAllSurveys()";
if($check1=mysqli_query($connection,$query1)){
	//get all surveys belong to this company
	$i=0;
	while($row= mysqli_fetch_assoc($check1)){
		$surveyID[$i]=$row['surveyId'];//get all surveyId's belong to this company
		$name[$i]=$row['questionName'];
		$state[$i]=$row['state'];
		$i+=1;
	}
?>
<h4>Surveys<h4>
<table border="5">
<?php
//showing surveys
for($count=0;$count<=$i;$count++){
?>
<tr>
  <td><?php echo $surveyID[$count]?></td>
  <td><?php echo $name[$count]?></td>
  <td><?php echo $state[$count]?></td>
</tr>
<?php
}
?>
</table>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
Select A Survey That You Want To Change The State Of Then Click "OK"
<select name="survey">
<?php
for($count=0;$count<$i;$count++){
?>
<option value="<?php echo $surveyID[$count]?>"><?php echo $surveyID[$count] ?></option>
<?php
}
?>
</select>
<select name="tempState">
<option value="0">Not Approved</option>
<option value="1">Approved</option>
<option value="2">Finish Survey</option>
</select>
<?php
}
?>
</select>
<input type="submit" name="OK" value="OK>>>">
<?php
}
mysqli_close($connection);
}
else
	die('Session Expired Please Login...');
?> 
